<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);

$servername = "localhost";
$username = "root"; // 数据库用户名
$password = "store"; // 数据库密码
$dbname = "aiweb"; // 数据库名称

// 创建连接
$conn = new mysqli($servername, $username, $password, $dbname);

// 检查连接
if ($conn->connect_error) {
    echo json_encode(['success' => false, 'message' => '连接失败: ' . $conn->connect_error]);
    exit;
}

// 获取要删除的 APPID
$appId = $_POST['appid'] ?? '';

if (empty($appId)) {
    echo json_encode(['success' => false, 'message' => 'APPID 不能为空']);
    exit;
}

// 删除应用记录
$sql = "DELETE FROM app WHERE appid = ?";
$stmt = $conn->prepare($sql);

if ($stmt === false) {
    echo json_encode(['success' => false, 'message' => '准备语句失败: ' . $conn->error]);
    exit;
}

$stmt->bind_param("s", $appId);

if ($stmt->execute()) {
    $response = ['success' => true];
} else {
    $response = ['success' => false, 'message' => '删除失败: ' . $stmt->error];
}

// 关闭连接
$stmt->close();
$conn->close();

// 返回 JSON 响应
header('Content-Type: application/json');
echo json_encode($response);
?>
